<?php

class Default_ItemsController extends ExtLb_Controller_Action
{
	private $postTbl;
	private $menu2Tbl;
	private $commentTbl;

    public function init(){
        $this->loadCss('default', 'item', FOLDER_ROOT_NAME);
        
        $this->postTbl		=	new Admin_Model_Posts();
        $this->menu2Tbl		= 	new Admin_Model_Menu2();
        $this->commentTbl 	= 	new Admin_Model_Comments();
        
        //RANDOM POST (BAI VIET NOI BAT)
    	$randPost = $this->postTbl->selectPost('bv.trangThai =1','baiVietId DESC',10)->query()->fetchAll();
    	$this->view->randPosts = $randPost;
    	
    	$this->view->comments = $this->commentTbl->selectComment(NULL,'yKienId DESC',5)->query()->fetchAll();
    }

    public function indexAction(){
        if (isset($_GET['mn']) && !empty($_GET['mn'])) {
        	$menu2Arr = $this->menu2Tbl->fetchColMenu2(array('menu2Id','tenMenu2'),'menu1Id ='.$_GET['mn']);
        	
        	$post =array();
        	foreach ($menu2Arr as $key=>$menu2) {
        		$post[$menu2['tenMenu2']]=  $this->postTbl
        										->selectPost(
        												'bv.menu2Id ='.$menu2['menu2Id'].
        												' and trangThai = 1',
        												'baiVietId DESC',
        												8
        										)
        										->query()->fetchAll();
        	}
        	
        	$this->view->posts = $post;
        	
        }else $this->_redirect('default/index');
    }


}

